package com.mszlu.blog.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mszlu.blog.common.Result;
import com.mszlu.blog.entity.SysUser;
import com.mszlu.blog.service.LoginService;
import com.mszlu.blog.service.SysUserServive;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@Transactional
public class CommonController {

    @Autowired
    private LoginService loginService;

    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    @PostMapping("/login")
    public Result login(@RequestBody SysUser user){

        return loginService.login(user);

    }

    @GetMapping("/logout")
    public Result logout(@RequestHeader("Authorization") String token){

        redisTemplate.delete("TOKEN_" + token);

        return Result.success(null);
    }

    @PostMapping("/register")
    public Result register(@RequestBody SysUser user){

        return loginService.register(user);

    }

}
